*Code preparatory/var making wwohPak

gen kammee = 0
replace kammee =1 if ancestor_occ==4
gen india=0
replace india=1 if migration_code==5
gen cousinmar = 0
replace cousinmar =1 if hw_cousin==1
gen w_Nchild=w_Nson+w_Ndaughter
gen w_NchildAlive= w_NsonAlive +w_NdaughterAlive

gen hh_age_ind1_th1 =0
replace hh_age_ind1_th1 =1 if hh_age_ind1 <=5
gen hh_age_ind1_th2 =0
replace hh_age_ind1_th2 =1 if hh_age_ind1 >5&hh_age_ind1 <=15
gen hh_age_ind1_th3 =0
replace hh_age_ind1_th3 =1 if hh_age_ind1 >15&hh_age_ind1!=.
gen hh_age_ind2_th1 =0
replace hh_age_ind2_th1 =1 if hh_age_ind2 <=5
gen hh_age_ind2_th2 =0
replace hh_age_ind2_th2 =1 if hh_age_ind2 >5&hh_age_ind2 <=15
gen hh_age_ind2_th3 =0
replace hh_age_ind2_th3 =1 if hh_age_ind2 >15&hh_age_ind2!=.
gen hh_age_ind3_th1 =0
replace hh_age_ind3_th1 =1 if hh_age_ind3 <=5
gen hh_age_ind3_th2 =0
replace hh_age_ind3_th2 =1 if hh_age_ind3 >5&hh_age_ind3 <=15
gen hh_age_ind3_th3 =0
replace hh_age_ind3_th3 =1 if hh_age_ind3 >15&hh_age_ind3!=.
gen hh_age_ind4_th1 =0
replace hh_age_ind4_th1 =1 if hh_age_ind4 <=5
gen hh_age_ind4_th2 =0
replace hh_age_ind4_th2 =1 if hh_age_ind4 >5&hh_age_ind4 <=15
gen hh_age_ind4_th3 =0
replace hh_age_ind4_th3 =1 if hh_age_ind4 >15&hh_age_ind4!=.
gen hh_age_ind5_th1 =0
replace hh_age_ind5_th1 =1 if hh_age_ind5 <=5
gen hh_age_ind5_th2 =0
replace hh_age_ind5_th2 =1 if hh_age_ind5 >5&hh_age_ind5 <=15
gen hh_age_ind5_th3 =0
replace hh_age_ind5_th3 =1 if hh_age_ind5 >15&hh_age_ind5!=.
gen hh_age_ind6_th1 =0
replace hh_age_ind6_th1 =1 if hh_age_ind6 <=5
gen hh_age_ind6_th2 =0
replace hh_age_ind6_th2 =1 if hh_age_ind6 >5&hh_age_ind6 <=15
gen hh_age_ind6_th3 =0
replace hh_age_ind6_th3 =1 if hh_age_ind6 >15&hh_age_ind6!=.
gen hh_age_ind7_th1 =0
replace hh_age_ind7_th1 =1 if hh_age_ind7 <=5
gen hh_age_ind7_th2 =0
replace hh_age_ind7_th2 =1 if hh_age_ind7 >5&hh_age_ind7 <=15
gen hh_age_ind7_th3 =0
replace hh_age_ind7_th3 =1 if hh_age_ind7 >15&hh_age_ind7!=.
gen hh_age_ind8_th1 =0
replace hh_age_ind8_th1 =1 if hh_age_ind8 <=5
gen hh_age_ind8_th2 =0
replace hh_age_ind8_th2 =1 if hh_age_ind8 >5&hh_age_ind8 <=15
gen hh_age_ind8_th3 =0
replace hh_age_ind8_th3 =1 if hh_age_ind8 >15&hh_age_ind8!=.
gen hh_age_ind9_th1 =0
replace hh_age_ind9_th1 =1 if hh_age_ind9 <=5
gen hh_age_ind9_th2 =0
replace hh_age_ind9_th2 =1 if hh_age_ind9 >5&hh_age_ind9 <=15
gen hh_age_ind9_th3 =0
replace hh_age_ind9_th3 =1 if hh_age_ind9 >15&hh_age_ind9!=.
gen hh_age_ind10_th1 =0
replace hh_age_ind10_th1 =1 if hh_age_ind10 <=5
gen hh_age_ind10_th2 =0
replace hh_age_ind10_th2 =1 if hh_age_ind10 >5&hh_age_ind10 <=15
gen hh_age_ind10_th3 =0
replace hh_age_ind10_th3 =1 if hh_age_ind10 >15&hh_age_ind10!=.
gen hh_age_ind11_th1 =0
replace hh_age_ind11_th1 =1 if hh_age_ind11 <=5
gen hh_age_ind11_th2 =0
replace hh_age_ind11_th2 =1 if hh_age_ind11 >5&hh_age_ind11 <=15
gen hh_age_ind11_th3 =0
replace hh_age_ind11_th3 =1 if hh_age_ind11 >15&hh_age_ind11!=.
gen hh_age_ind12_th1 =0
replace hh_age_ind12_th1 =1 if hh_age_ind12 <=5
gen hh_age_ind12_th2 =0
replace hh_age_ind12_th2 =1 if hh_age_ind12 >5&hh_age_ind12 <=15
gen hh_age_ind12_th3 =0
replace hh_age_ind12_th3 =1 if hh_age_ind12 >15&hh_age_ind12!=.
gen hh_age_ind13_th1 =0
replace hh_age_ind13_th1 =1 if hh_age_ind13 <=5
gen hh_age_ind13_th2 =0
replace hh_age_ind13_th2 =1 if hh_age_ind13 >5&hh_age_ind13 <=15
gen hh_age_ind13_th3 =0
replace hh_age_ind13_th3 =1 if hh_age_ind13 >15&hh_age_ind13!=.
gen hh_age_ind14_th1 =0
replace hh_age_ind14_th1 =1 if hh_age_ind14 <=5
gen hh_age_ind14_th2 =0
replace hh_age_ind14_th2 =1 if hh_age_ind14 >5&hh_age_ind14 <=15
gen hh_age_ind14_th3 =0
replace hh_age_ind14_th3 =1 if hh_age_ind14 >15&hh_age_ind14!=.

gen ninfant = hh_age_ind1_th1 + hh_age_ind2_th1 +hh_age_ind3_th1 +hh_age_ind4_th1 +hh_age_ind5_th1 +hh_age_ind6_th1 +hh_age_ind7_th1 +hh_age_ind8_th1 +hh_age_ind9_th1 +hh_age_ind10_th1 +hh_age_ind11_th1 +hh_age_ind12_th1 +hh_age_ind13_th1 +hh_age_ind14_th1
gen nchild = hh_age_ind1_th2 + hh_age_ind2_th2 +hh_age_ind3_th2 +hh_age_ind4_th2 +hh_age_ind5_th2 +hh_age_ind6_th2 +hh_age_ind7_th2 +hh_age_ind8_th2 +hh_age_ind9_th2 +hh_age_ind10_th2 +hh_age_ind11_th2 +hh_age_ind12_th2 +hh_age_ind13_th2 +hh_age_ind14_th2  
gen nadult = hh_age_ind1_th3 + hh_age_ind2_th3 +hh_age_ind3_th3 +hh_age_ind4_th3 +hh_age_ind5_th3 +hh_age_ind6_th3 +hh_age_ind7_th3 +hh_age_ind8_th3 +hh_age_ind9_th3 +hh_age_ind10_th3 +hh_age_ind11_th3 +hh_age_ind12_th3 +hh_age_ind13_th3 +hh_age_ind14_th3  
gen nhh = ninfant+nchild+nadult

replace v_remit=0 if v_remit==.
gen remit_10000 = v_remit/10000
gen farmvalue =farmland*acrevalue
replace farmvalue=0 if farmvalue==.
gen v_bankcash=v_bankacc
replace v_bankcash=0 if v_bankacc==.
gen hhinc_10000 =totalhh_inc/10000
gen residence=v_homeplusland/10000
gen ls=v_livestock/10000

*factor analysis on qol
factor bicycle motorbike car washmachine sewmachine generator tv ac cellphone fridge, pf
rotate, promax
predict fac_corr1

gen myopic1=5000-s_advance
gen myopic2=s_late-1000
gen timeinc1=0
replace timeinc1=1 if (s_advance<5000)&(s_late<=1000)|(s_advance>=5000)&(s_late>1000)
gen timeinc2=0 
replace timeinc2=1 if s_disc1!=s_disc2
gen riskpre=0
replace riskpre=1 if s_risk==2
gen sonpre=0
replace sonpre=1 if s_idealboys>s_idealgirls
gen myopic=myopic1+myopic2
gen flfpRF=flfp_relative+flfp_friend

*factor analysis on s_flfp
factor s_flfp1 s_flfp2 s_flfp3 s_flfp4, pf
rotate, promax
predict flfppre

gen flfppre_bm =s_flfp1+s_flfp3
gen flfppre_am =s_flfp2+s_flfp4
gen flfppre_gen=s_flfp1+s_flfp2
gen flfppre_tea=s_flfp3+s_flfp4

gen dm_cook_w=0
replace dm_cook_w=1 if dm_cook==2
gen dm_expensive_w=0
replace dm_expensive_w=1 if dm_expensive==2
gen dm_child_w=0
replace dm_child_w=1 if dm_child==2
gen dm_sickchild_w=0
replace dm_sickchild_w=1 if dm_sickchild==2
gen dm_visit_w=0
replace dm_visit_w=1 if dm_visit==2
gen dm_burka_w=0
replace dm_burka_w=1 if dm_burka==2
gen dm_sonjob_w=0
replace dm_sonjob_w=1 if dm_sonjob==2
gen dm_flfp_w=0
replace dm_flfp_w=1 if dm_flfp==2
gen dm_flfp_job_w=0
replace dm_flfp_job_w=1 if dm_flfp_job==2
gen dm_childmarriage_w=0
replace dm_childmarriage_w=1 if dm_childmarriage==2

*factor analysis on dm
factor dm_cook_w dm_expensive_w dm_child_w dm_sickchild_w dm_visit_w dm_burka_w dm_sonjob_w dm_flfp_w dm_flfp_job_w dm_childmarriage_w, pf
rotate, promax
predict dm

gen veg_w=0
replace veg_w=1 if who_veggieshop==2
gen genbias1=0
replace genbias1=1 if mealtime==3

*factor analysis on lc
factor o3 o4 o5, pf
rotate, promax
predict fac_lc

*label
label var No "household-round identifier"
label var HHID "household identifier"
label var Treated "treatment status"
label var villageNo "village identifier"
label var tehsilNo "tehsil identifier"
label var districtNo	"district identifier"
label var sex	"treated gender"
label var h_1stmar	"husband 1st marriage"
label var w_1stmar	"wife 1st marriage"
label var h_edu	"husband education"
label var w_edu	"wife education"
label var h_lit "husband literacy"
label var w_lit	"wife literacy"
label var h_brN	"husband number of brothers"
label var h_sisN	"husband number of sisters"
label var w_brN	"wife number of brothers"
label var w_sisN	"wife number of sisters"
label var h_marage	"husband marriage age"
label var h_marage2	"husband marriage age (2nd)"
label var w_marage	"wife marriage age"
label var w_marage2	"wife marriage age (2nd)"
label var hw_relate	"husband wife related"
label var hw_cousin	"husband wife related"
label var hw_relate_what	"husband wife relationship"
label var w_natalmin	"minutes taken to wife's natal household"
label var w_Nson	"wife number of sons"
label var w_Ndaughter	"wife number of daughters"
label var w_NsonAlive	"wife number of living sons"
label var w_NdaughterAlive	"wife number of living daughters"
label var w_age_birth	"wife age at first birth"
label var biradari	"biradari name"
label var biradariNo	"biradari English name"
label var ancestor_occ	"ancestor occupation"
label var anc_occ_what	"ancestor occupation name"
label var migration	"migrated"
label var migration_code	"migration code"
label var migration_where	"migration from where"
label var migration_ago	"migration years ago"
label var migration_hr	"minutes taken to the original place"
label var ethnic	"ethnicity code"
label var religion	"religion code"

foreach i of num 1/14 {
	label var hh_relate_ind`i'	"Individual `i': Relationship to head of household"
	label var hh_age_ind`i'	"Individual `i': age"
	label var hh_sex_ind`i'	"Individual `i': gender"
	label var hh_enroll_ind`i'	"Individual `i': currently enrolled"
	label var hh_edu_ind`i'	"Individual `i': completed level of education"
	label var hh_wfp_ind`i'	"Individual `i': work for payment"
 }

label var n_remit	"number of labor migrants"
label var v_remit	"PKR value of remittances last 12 months"
label var farmland	"acre of agricultural land"
label var acrevalue	"PKR value per acre"
label var agrirent	"acre of agricultural land rent"
label var rent_cash	"types of rent payment"
label var v_agrirent	"PKR value of agricultural rent last 12 months"
label var q_wheat	"quantity wheat production"
label var q_fodder	"quantity fodder production"
label var q_rice	"quantity rice production"
label var q_sc	"quantity sugarcane production"
label var q_veg	"quantity vegetable production"
label var q_maize	"quantity maize production"
label var q_peanut	"quantity peanut production"
label var q_cotton	"quantity cotton production"
label var q_wheat_sold	"quantity wheat sold"
label var q_fodder_sold	"quantity fodder sold"
label var q_rice_sold	"quantity rice sold"
label var q_sc_sold	"quantity sugarcane sold"
label var q_veg_sold	"quantity vegetable sold"
label var q_maize_sold	"quantity maize sold"
label var q_peanut_sold	"quantity peanut sold"
label var q_cotton_sold	"quantity cotton sold"
label var gv_wheat	"PKR gross value wheat sold"
label var gv_fodder	"PKR gross value fodder sold"
label var gv_rice	"PKR gross value rice sold"
label var gv_sc	"PKR gross value sugarcane sold"
label var gv_veg	"PKR gross value vegetable sold"
label var gv_maize	"PKR gross value maize sold"
label var gv_peanut	"PKR gross value peanut sold"
label var gv_cotton	"PKR gross value cotton sold"
label var pft_wheat	"PKR net profit value wheat sold"
label var pft_fodder	"PKR net profit value fodder sold"
label var pft_rice	"PKR net profit value rice sold"
label var pft_sc	"PKR net profit value sugarcane sold"
label var pft_veg	"PKR net profit value vegetable sold"
label var pft_maize	"PKR net profit value maize sold"
label var pft_peanut	"PKR net profit value peanut sold"
label var pft_cotton	"PKR net profit value cotton sold"
label var pft_sum	"PKR net profit total last 12 months"
label var livestock	"livestock owned"
label var buffalo	"number of buffalos"
label var cattle	"number of cattle"
label var goat	"number of goats"
label var sheep	"number of sheep"
label var chicken	"number of chickens"
label var donkey	"number of donkeys"
label var calf	"number of calves"
label var mual	"number of murals"
label var p_buffalo	"unit price of buffalos"
label var p_cattle	"unit price of cattle"
label var p_goat	"unit price of goats"
label var p_sheep	"unit price of sheep"
label var p_chicken	"unit price of chickens"
label var p_donkey	"unit price of donkeys"
label var p_calf	"unit price of calves"
label var p_mual	"unit price of murals"
label var v_livestock	"PKR total value of livestock"
label var livestock_sold	"PKR net profit of livestock sold last 12 months"
label var mik_sold	"PKR net profit of milk/eggs sold last 12 months"

foreach i of num 1/7 {
	label var occ`i'	"Occupation `i': income source"
	label var occ_what`i'	"Occupation `i': income source name"
	label var occ_hhre`i'	"Occupation `i': primary earner"
	label var occ_inc`i'	"Occupation `i': PKR income last 12 months"
 }

label var totalhh_inc	"PKR total household income last 12 months"
label var homeland	"marla residential land owned"
label var v_home	"PKR value of home"
label var v_homeland	"PKR value of residential land"
label var v_homeplusland	"PKR value of residential home and land"
label var v_homerent	"PKR value of residential monthly rent"
label var cash	"PKR value of cash "
label var bankacc	"bank account"
label var v_bankacc	"PKR value of bank account"
label var bicycle	"ownership: bicycle"
label var motorbike	"ownership: motorbike"
label var car	"ownership: car"
label var washmachine	"ownership: washing machine"
label var sewmachine	"ownership: sewing machine"
label var generator	"ownership: generator"
label var tv	"ownership: tv"
label var fan	"ownership: fan"
label var ac	"ownership: air conditioner"
label var cellphone	"ownership: cellphone"
label var fridge	"ownership: fridge"
label var e_food	"PKR expenditure value of staple food last 7 days"
label var e_egg	"PKR expenditure value of egg/dairy products last 7 days"
label var e_fruit	"PKR expenditure value of fruits last 7 days"
label var e_veg	"PKR expenditure value of vegetables last 7 days"
label var e_meat	"PKR expenditure value of meat/fish last 7 days"
label var e_snack	"PKR expenditure value of snacks last 7 days"
label var e_sugar	"PKR expenditure value of sugar last 7 days"
label var e_tea	"PKR expenditure value of tea last 7 days"
label var e_otbever	"PKR expenditure value of other beverage last 7 days"
label var e_tobacco	"PKR expenditure value of tobacco last 7 days"
label var e_transport	"PKR expenditure value of transportation and fuels last 7 days"
label var e_enter	"PKR expenditure value of entertainment recreation last 7 days"
label var e_utility	"PKR expenditure value of utility last month"
label var e_cloth	"PKR expenditure value of clothing last 12 months"
label var e_school	"PKR expenditure value of school last 12 months2"
label var e_detergent	"PKR expenditure value of detergent last 7 days"
label var e_ceremony	"PKR expenditure value of ceremony last 12 months"
label var e_medicine	"PKR expenditure value of medicine last 12 months"
label var e_msum	"PKR expenditure value monthly items"
label var e_asum	"PKR expenditure value annual items"
label var e_sum	"PKR expenditure value total"
label var n_loan 	"number of loans last 5 years"
label var v_loan	"PKR value of the most expensive loan"
label var dur_loan_yr	"duration of the most expensive loan"
label var why_loan	"reason of the most expensive loan"
label var loan_from	"lender"
label var loan_from_whom "lender specific name"
label var loan_biradari "the same biradari lender"
label var interest	"annual interest rate"
label var v_interest	"value of interest"
label var loan_paid "loan already paid off"
label var v_borrow	"PKR total amount owing to others"
label var v_lend	"PKR total amount to be paid by others"
label var dowry	"PKR expected amount of dowry"
label var ceremony	"PKR expected expenditure marriage ceremony"
label var hard_marex	"difficulty raising marriage expenditure"
label var how_marex	"how to raise marriage expenditure"
label var how_marex_who	"name how to raise marriage expenditure"
label var friend_marex	"number of friends potential lenders"
label var relative_marex	"number of relatives potential lenders"
label var d_choice	"daughter marital choice"
label var d_groom	"daughter potential groom"
label var d_groom_far	"daughter potential groom minutes distance"
label var d_groom_edu	"daughter potential groom education"
label var d_groom_inc	"PKR daughter potential groom expected annual income"
label var d_groom_cousin	"daughter potential groom 1st cousin"
label var d_Ncousin	"daughter number of marriageable 1st cousins"
label var d_Ncomp	"daughter number of same sex 1st cousins that can be potential competitors"
label var d_watta	"daughter marriage in watta satta"
label var d_endvillage	"daughter marriage within the village"
label var d_joint	"daughter joint marriage"
label var d_joint_who	"daughter who joint marry"
label var s_advance	"PKR advance payment"
label var s_late	"PKR late payment"
label var s_risk	"risk preference"
label var s_disc1	"time inconsistency week"
label var s_disc2	"time inconsistency year"
label var s_fuelhard	"difficulty in utility payment"
label var s_mealhard	"difficulty purchasing food"
label var s_loan_fr	"asking loans from friends/relatives"
label var s_loan_nonfr	"asking loans from non friends/relatives"

foreach i of num 1/4 {
	label var s_save`i' "saving attitude `i'"
	label var s_flfp`i' "attitude toward female labor force participation `i'"
 }

label var s_girledu	"girls boys equal education"
label var s_flfp_no	"reason against women working outside"
label var s_flfp_yes	"reason for women working outside"
label var s_idealboys	"ideal number of boys"
label var s_idealgirls	"ideal number of girls"
label var s_goal	"any future goals?"
label var s_goal_short	"name short-term goal"
label var s_goal_med	"name medium-term goal"
label var s_goal_long	"name long-term goal"
label var flfp_info	"information of women's working opportunities"
label var flfp	"know women working outside for pay"
label var flfp_relative	"number of female relatives working outside for pay"
label var flfp_friend	"number of female friends working outside for pay"
label var minwage_info	"know minimum wage"
label var minwage	"PKR minimum wage"
label var rv_wage	"PKR reservation wage for daughter working outside for pay"
label var teachwage_info	"know private teacher wage"
label var teachwage	"PKR teacher wage"
label var dm_cook	"who decide what to cook"
label var dm_cook_who	"name who decide what to cook"
label var dm_expensive	"who decide purchase of expensive items"
label var dm_expensive_who	"name who decide purchase of expensive items"
label var dm_child	"who decide number of children"
label var dm_child_who	"name who decide number of children"
label var dm_sickchild	"who decide what to do with a sick child"
label var dm_visit	"who decide wife visiting friends/relatives"
label var dm_burka	"who decide whether wife wear burqa"
label var dm_sonjob	"who decide what job son should take"
label var dm_sonjob_who	"name who decide what job son should take"
label var dm_flfp	"who decide whether daughter should work"
label var dm_flfp_who	"name who decide whether daughter should work"
label var dm_flfp_job	"who decide what job daughter should take"
label var dm_flfp_job_who	"name who decide what job daughter should take"
label var dm_childmarriage	"who decide to whom child should marry"
label var dm_childmarriage_who	"name who decide to whom child should marry"
label var who_veggieshop	"who vegetable shopping"
label var w_veggieshop	"wife shops for vegetables"
label var mealtime	"dinner timing"
label var o1	"interviewer observation: who responded"
label var o2	"interviewer observation: male member presence"
label var o2a	"interviewer observation: husband presence"
label var o2b	"interviewer observation: father-in-law presence"
label var o2c	"interviewer observation: brother-in-law presence"
label var o2d	"interviewer observation: other presence"
label var o2d_who	"interviewer observation: name who"
label var o3	"interviewer observation: wall type"
label var o4	"interviewer observation: roof type"
label var o5	"interviewer observation: floor type"
label var D_married	"daughter married at the endline"
label var S_married	"son married the endline"
label var M_died	"mother died at the endline"
label var Year2	"endline"
label var Vpercent	"% of treated households in the village"
label var v_treatment_type	"treatment type"
label var v_pop	"total population"
label var v_hhnumber	"total number of households"
label var v_unmarWoman	"number of unmarried women aged 15-30"
label var v_unmarMan	"number of unmarried men aged 20-35"
label var v_unmar_factory	"number of unmarried working women in the factory"
label var v_unmar_teacher	"number of unmarried female teachers"
label var v_area	"hectares village are"

foreach i of num 1/6 {
	label var v_bira_zamin`i'	"biradari `i' land share"
 }

label var v_plowwage1	"PKR daily wage plowing, kharif, men"
label var v_plowwage4	"PKR daily wage plowing, rabi, men"
label var v_sowwage1	"PKR daily wage sowing, kharif, men"
label var v_harwage1	"PKR daily wage harvesting, kharif, men"
label var v_harwage3	"PKR daily wage harvesting, kharif, children<15"
label var v_harwage4	"PKR daily wage harvesting, rabi, men"
label var v_harwage5	"PKR daily wage harvesting, rabi, women"
label var v_harwage6	"PKR daily wage harvesting, rabi, children<15"
label var v_hkwage1	"PKR daily wage housekeeping, men"
label var v_hkwage2	"PKR daily wage housekeeping, women"
label var v_hkwage3	"PKR daily wage housekeeping, children<15"
label var v_unskillwage1	"PKR daily wage unskilled, men"
label var v_cnstwage1	"PKR daily wage skilled, men"

label var v_cbl_min	"minutes taken to CBL or Pindi Bhattian"
label var v_mtm_min	"minutes taken to MTM or 32km Sheikhupura-Faisalabad Road"

label var v_town	"name nearest town"
label var v_town_min	"minutes taken to nearest town"

foreach i of num 1/3 {
	label var v_water`i'	"source of drinking water `i'"
	label var v_fuel`i'	"source of cooking fuel `i'"
 }
 
label var v_bus	"minutes taken to closest bus stop"

*var making
gen intT=Treated*Year2
gen Dminrv_wage=rv_wage-minwage
gen Tsex=0
replace Tsex=1 if sex==1
gen intTsex=Tsex*Treated

gen Tgroup=0
replace Tgroup=1 if v_treatment_type==1
gen Tind=0
replace Tind=1 if v_treatment_type==2

egen zflfp1=std(s_flfp1) 
egen zflfp2=std(s_flfp2) 
egen zflfp3=std(s_flfp3) 
egen zflfp4=std(s_flfp4) 
egen temp=rowtotal(zflfp*)
egen zflfp=std(temp)
drop temp
gen temp0=zflfp if Year2==0
gen temp1=zflfp if Year2==1
sort HHID 
by HHID : egen zflfpidx_0=total(temp0)
by HHID : egen zflfpidx_1=total(temp1)
drop temp0 temp1

gen info4=0
replace info4=1 if flfp_info2==1|flfp_info2==2
gen info5=0
replace info5=1 if flfp_info2==2
gen info6=0
replace info6=1 if flfp_info3==1|flfp_info3==2
gen info7=0
replace info7=1 if flfp_info3==2

gen temp0=flfp_info2 if Year2==0
gen temp1=flfp_info2 if Year2==1
sort HHID 
by HHID : egen flfp_info2_0=total(temp0)
by HHID : egen flfp_info2_1=total(temp1)
drop temp0 temp1
gen temp0=flfp_info3 if Year2==0
gen temp1=flfp_info3 if Year2==1
sort HHID 
by HHID : egen flfp_info3_0=total(temp0)
by HHID : egen flfp_info3_1=total(temp1)
drop temp0 temp1
gen temp0=flfp_info if Year2==0
gen temp1=flfp_info if Year2==1
sort HHID 
by HHID : egen flfp_info_0=total(temp0)
by HHID : egen flfp_info_1=total(temp1)
drop temp0 temp1
gen temp0=flfppre_bm if Year2==0
gen temp1=flfppre_bm if Year2==1
sort HHID 
by HHID : egen flfppre_bm_0=total(temp0)
by HHID : egen flfppre_bm_1=total(temp1)
drop temp0 temp1
gen temp0=flfppre_am if Year2==0
gen temp1=flfppre_am if Year2==1
sort HHID 
by HHID : egen flfppre_am_0=total(temp0)
by HHID : egen flfppre_am_1=total(temp1)
drop temp0 temp1
gen temp0=flfppre_gen if Year2==0
gen temp1=flfppre_gen if Year2==1
sort HHID 
by HHID : egen flfppre_gen_0=total(temp0)
by HHID : egen flfppre_gen_1=total(temp1)
drop temp0 temp1
gen temp0=flfppre_tea if Year2==0
gen temp1=flfppre_tea if Year2==1
sort HHID 
by HHID : egen flfppre_tea_0=total(temp0)
by HHID : egen flfppre_tea_1=total(temp1)
drop temp0 temp1
gen temp0=flfppre if Year2==0
gen temp1=flfppre if Year2==1
sort HHID 
by HHID : egen flfppre_0=total(temp0)
by HHID : egen flfppre_1=total(temp1)
drop temp0 temp1
gen temp0=Dminrv_wage if Year2==0
gen temp1=Dminrv_wage if Year2==1
sort HHID 
by HHID : egen Dminrv_wage_0=total(temp0)
by HHID : egen Dminrv_wage_1=total(temp1)
gen percapFarm=farmland/nhh
drop temp0 temp1

gen info4_re1=0
replace info4_re1=1 if flfp_info2_1==1|flfp_info2_1==2
gen info4_re0=0
replace info4_re0=1 if flfp_info2_0==1|flfp_info2_0==2
gen info5_re1=0
replace info5_re1=1 if flfp_info2_1==2
gen info5_re0=0
replace info5_re0=1 if flfp_info2_0==2
gen info6_re1=0
replace info6_re1=1 if flfp_info3_1==1|flfp_info3_1==2
gen info6_re0=0
replace info6_re0=1 if flfp_info3_0==1|flfp_info3_0==2
gen info7_re1=0
replace info7_re1=1 if flfp_info3_1==2
gen info7_re0=0
replace info7_re0=1 if flfp_info3_0==2
